package cn.new7as.cas5s.ui.record;

import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import java.util.List;

import cn.new7as.cas5s.R;
import cn.new7as.cas5s.tool.util.Utils;
import cn.new7as.cas5s.ui.easy.netapi.OrderApi;

public class SelectOrdersadapter extends BaseAdapter {

    private List<OrderApi.Data> list;
    private SelectOrdersActivity context;


    public SelectOrdersadapter(List<OrderApi.Data> list, SelectOrdersActivity context) {
        super();

        this.context = context;
        this.list = list;

    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }


    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        ViewHolder viewHolder = null;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.layout_grid_selectorders, parent, false);
            viewHolder = new ViewHolder();
            viewHolder.pending = (TextView) convertView.findViewById(R.id.pending);

            viewHolder.ramount = (TextView) convertView.findViewById(R.id.ramount);

            viewHolder.scheduledrepaymentdate = (TextView) convertView.findViewById(R.id.scheduledrepaymentdate);

            viewHolder.update = (TextView) convertView.findViewById(R.id.select);
            viewHolder.ordname = (TextView) convertView.findViewById(R.id.ordname);
            viewHolder.scheduledrepaymentdate = (TextView) convertView.findViewById(R.id.scheduledrepaymentdate);


            convertView.setTag(viewHolder);

        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        viewHolder.ramount.setText(list.get(position).predictTotalCapital);

        viewHolder.scheduledrepaymentdate.setText(list.get(position).repayMentDate);
        viewHolder.ordname.setText(list.get(position).productCategoryName);
        int i = Utils.getordStaus(list.get(position));

        if (i == 1) {
            viewHolder.pending.setText(R.string.overdue);
            viewHolder.pending.setTextColor(Color.parseColor("#ff4242"));


        } else if (i == 2) {
            viewHolder.pending.setText("");

        } else if (i == 3) {

            viewHolder.pending.setText(R.string.pending);
            viewHolder.pending.setTextColor(Color.parseColor("#19c656"));
        } else if (i == 4) {
            viewHolder.pending.setText(R.string.rejected);
            viewHolder.pending.setTextColor(Color.parseColor("#0a0c06"));

        } else if (i == 5) {

            viewHolder.pending.setText(R.string.settled);
            viewHolder.pending.setTextColor(Color.parseColor("#5e6157"));
        } else if (i == 6) {

            viewHolder.update.setVisibility(View.VISIBLE);
            viewHolder.pending.setText(R.string.payment_failed);
            viewHolder.pending.setTextColor(Color.parseColor("#5e6157"));

        }

        viewHolder.update.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                context.setBack(list.get(position).tradeNo);


            }
        });


        return convertView;
    }

    class ViewHolder {
        TextView pending;

        TextView ramount;
        TextView extendfee;
        TextView scheduledrepaymentdate;

        TextView update;
        TextView ordname;

    }
}
